package sg.edu.nus.iss.billing.service.subscription;

import java.util.Iterator;
import java.util.List;

import sg.edu.nus.iss.billing.common.Util;
import sg.edu.nus.iss.billing.dao.subscription.SubscriptionDAO;
import sg.edu.nus.iss.billing.vo.subscription.CableTvVO;
import sg.edu.nus.iss.billing.vo.subscription.DigitalVoiceVO;
import sg.edu.nus.iss.billing.vo.subscription.MobileVoiceVO;
import sg.edu.nus.iss.billing.vo.subscription.SubscriptionVO;

public class DigitalVoice extends Voice {

	@Override
	boolean canTerminate(String accountNo) {
		
		boolean result= true;
		SubscriptionDAO subscriptionDAO = new SubscriptionDAO();
		
		List<SubscriptionVO> subscribedPlanList=  subscriptionDAO.getSubscriptionForAcct(accountNo);
		for(Iterator<SubscriptionVO> subscribed = subscribedPlanList.iterator(); subscribed.hasNext(); ) {
			//Subscription Main Plan
			 SubscriptionVO subscribedPlan = subscribed.next();
		
	         //DigitalVoice
	         if(subscribedPlan instanceof DigitalVoiceVO)
	         {
	        	 DigitalVoiceVO digitalVoiceVO = (DigitalVoiceVO)subscribedPlan;
	        	 if(digitalVoiceVO.getStatus().equals(Util.ACCOUNT_STATUS_ACTIVE))
	        	 {
	        		//If start date if after the today date - 3 months
	        		 if(digitalVoiceVO.getStartDate().compareTo(Util.dateAddMonth(Util.getSystemDate(), -3))>0)
	        		 {
	        			 result = false;
	        			 break;
	        		 }
	        	 }
	         }
	        
	        
	         
		}
		
		return result;
	}

}
